import 'package:flutter/material.dart';
import 'package:flutter_app/components/layout.dart';
import 'package:flutter_app/components/no-record.dart';
import 'package:flutter_app/utils/AppUtil.dart';
import 'package:flutter_app/generated/l10n.dart';

class WalletDetailPage extends StatefulWidget {
  @override
  _WalletDetailPageState createState() => _WalletDetailPageState();
}

Widget RecommendItemContainer(context, RecommendItem item) {
  return GestureDetector(
    onTap: () => Navigator.pushNamed(context, item.url),
    child: Container(
      padding: EdgeInsets.symmetric(vertical: 15.0),
      child: RowBetween(children: [
        Expanded(
          child: Container(
            color: Colors.transparent,
            child: Row(
              children: [
                Image.asset(
                  item.img,
                  width: 35,
                ),
                SizedBox(
                  width: 10.0,
                ),
                Text(item.text)
              ],
            ),
          ),
        ),
        Icon(
          Icons.arrow_forward_ios_outlined,
          size: 14,
          color: Colors.grey,
        )
      ]),
    ),
  );
}

class RecommendItem {
  String img;
  String text;
  String url;

  RecommendItem({this.img, this.text, this.url});
}

List<RecommendItem> RecommendItems = [
  RecommendItem(
      img: 'assets/images/ic_product_list_dual_ccy_btc.png',
      text: 'BTC双币 - 挂钩BTC价格稳中求进',
      url: '/double'),
  RecommendItem(
      img: 'assets/images/ic_product_list_bull_punter.png',
      text: '看币涨跌 - 博取BTC方向性波动收益',
      url: '/'),
  RecommendItem(
      img: 'assets/images/ic_product_list_time_deposit.png',
      text: '固收投资 - 保本投资收益稳健',
      url: '/fixed'),
  RecommendItem(
      img: 'assets/images/ic_product_list_triple_bull.png',
      text: '一键囤币 - 享最高5倍杠杆收益',
      url: '/lever'),
];

List<Widget> getRecommendItems(context) {
  return RecommendItems.map((item) {
    return RecommendItemContainer(context, item);
  }).toList();
}

class _WalletDetailPageState extends State<WalletDetailPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  String address = '1QWJIQWWQWJKWQJWLJIIWIWIIIII';
  List<String> tabs = List(3);

  @override
  void initState() {
    super.initState();
    /*Future.delayed(Duration.zero, () {
      //执行代码写在这里
      //全部  充币  提币
       tabs = [S.of(context).all, S.of(context).deposit, "提币"];
    });*/

    // 创建Controller
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  void showRecommend() {
    // 推荐投资
    GetBottomSheet(context,
        text: S.of(context).recommended_investment,
        height: 320,
        padding: EdgeInsets.symmetric(horizontal: 15.0),
        children: getRecommendItems(context));
  }

  @override
  Widget build(BuildContext context) {
    tabs = [S.of(context).all, S.of(context).deposit, S.of(context).withdraw];

    return Scaffold(
      appBar: DarkHeadBar('BTC'),
      body: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
        child: Column(
          children: [
            Expanded(
                child: Column(
              children: [
                Image.asset("assets/images/ic_btc.png", width: 40),
                SizedBox(height: 15.0),
                Text(
                  '0.0000',
                  style: TextStyle(
                      color: Colors.black,
                      fontSize: 20,
                      fontWeight: FontWeight.w500),
                ),
                SizedBox(
                  height: 10.0,
                ),
                Text(
                  '≈\$0.00',
                  style: TextStyle(color: Colors.grey),
                ),
                GreyContainer(
                    margin: EdgeInsets.symmetric(vertical: 15.0),
                    padding:
                        EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
                    child: RowBetween(
                      children: [
                        Text(
                          address,
                          style: TextStyle(color: Colors.grey, fontSize: 12),
                        ),
                        GestureDetector(
                            onTap: () {
                              AppUtil.copy(address,
                                  successMsg: S.of(context).copy_success);
                            },
                            child: Icon(
                              Icons.copy_outlined,
                              color: Colors.grey,
                              size: 16,
                            ))
                      ],
                    )),
                Container(
                  padding: EdgeInsets.only(bottom: 5.0),
                  decoration: BoxDecoration(
                      border: Border(
                    top: BorderSide(color: Theme.of(context).dividerColor),
                    bottom: BorderSide(color: Theme.of(context).dividerColor),
                  )),
                  child: TabBar(
                      //生成Tab菜单
                      controller: _tabController,
                      labelColor: Colors.blueAccent,
                      unselectedLabelColor: Colors.grey,
                      indicatorColor: Colors.blueAccent,
                      indicatorSize: TabBarIndicatorSize.label,
                      indicatorWeight: 3.0,
                      tabs: tabs.map((e) => Tab(text: e)).toList()),
                ),
                Expanded(child: NoRecord())
              ],
            )),
            RowBetween(
              children: [
                //提币
                FlatButton(
                  onPressed: () {
                    Navigator.pushNamed(context, '/safe/warning');
                  },
                  child: Text(S.of(context).withdraw),
                  color: Colors.blue.withOpacity(0.08),
                  textColor: Colors.blueAccent,
                ),
                // 充币
                FlatButton(
                  onPressed: () {
                    Navigator.pushNamed(context, '/trade/charge');
                  },
                  child: Text(S.of(context).deposit),
                  color: Colors.blueAccent,
                  textColor: Colors.white,
                ),
                //投资
                FlatButton(
                  onPressed: showRecommend,
                  child: Text(S.of(context).invest),
                  color: Colors.blueAccent,
                  textColor: Colors.white,
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
